package com.demo.model;

import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.validation.constraints.AssertFalse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@Document(indexName = "luna_order")
public class Order {
    @Id
    @Excel(name = "订单ID")
    private Long orderId;
    private String orderSn;
    private String address;

    /**
     * 购买日期
      */
    @Excel(name = "购买日期", format = "yyyy年MM月dd日")
    private Date dateOfPurchase;
    private BigDecimal price;
    /**
     * 固话
      */
    private String tel;
    /**
     * 手机
      */
    private String mobileTel;

    @Field(type = FieldType.Nested)
    private List<OrderDetail> detail;

    @AssertFalse(message = "tel,mobile字段不能同时为空")
    private boolean isValid() {
        return StringUtils.isAllBlank(tel, mobileTel);
    }
}
